Event.observe(document, 'dom:loaded', function() {

    prettyPrint();

    HumbleFinance.trackFormatter = function (obj) {

        var x = Math.floor(obj.x);
        var text = jsonData[x] + " Value: " + priceData[x][1];
        $('dataPoint').update(text);
        return text;
    };

    HumbleFinance.yTickFormatter = function (n) {

        if (n == this.axes.y.max) {
            return false;
        }

        return n;
    };

    HumbleFinance.xTickFormatter = function (n) {

        if (n == 0) {
            return false;
        }

        var date = jsonData[n];
        return date;
    }

    HumbleFinance.init('metric', priceData, summaryData);

    var xaxis = HumbleFinance.graphs.summary.axes.x;
    var prevSelection = HumbleFinance.graphs.summary.prevSelection;
    var xmin = xaxis.p2d(prevSelection.first.x);
    var xmax = xaxis.p2d(prevSelection.second.x);

    $('dateRange').update(jsonData[xmin]+ ' - ' + jsonData[xmax]);

    Event.observe(HumbleFinance.containers.summary, 'flotr:select', function (e) {

        var area = e.memo[0];
        xmin = Math.floor(area.x1);
        xmax = Math.ceil(area.x2);

        var date1 = jsonData[xmin];
        var date2 = jsonData[xmax];

        $('dateRange').update(jsonData[xmin] + ' - ' + jsonData[xmax]);
    });
});
